<template>
  <view class="u-m-t-20">
    <u-cell-group v-if="phaseList.length !== 0" class="has-radius">
      <view 
        class="u-p-10"
        v-for="(item,index) in phaseList"
        >
        <u-cell-item
          :title="`${item.phaseName} (${item.completedCount}/${item.total})`"
          @click="
            gotoClick(
              item,
              `${item.phaseName} (${item.completedCount}/${item.total})`
            )
          "
          :border-bottom="index !== phaseList.length - 1"
        ></u-cell-item>
      </view>
    </u-cell-group>
    <view class="empty">
      <u-empty
        text="暂无数据"
        mode="data"
        v-if="phaseList.length === 0"
      ></u-empty>
    </view>
  </view>
</template>
<script lang="ts" setup>
import { onLoad } from '@dcloudio/uni-app';
import { getPhaseList } from '@/api/modules/project';

const props = defineProps<{
  projectInfo: any;
}>();
const { projectInfo } = toRefs(props);

const phaseList = ref<any[]>([]);
const queryPhaseList = () => {
  const params = {
    projectId: projectInfo.value.projectId,
    sortType: 1,
    selfTask: false,
  };
  console.log('params', projectInfo.value);
  getPhaseList(params).then((res: any) => {
    phaseList.value = res;
  });
};

queryPhaseList();

const gotoClick = (data: any, title: string) => {
  if (!data.total) {
    uni.showToast({
      title: '该阶段暂无数据',
      icon: 'none',
      duration: 2000,
    });
    return;
  }
  (uni as any).$Router.push({
    name: 'phaseTaskList',
    params: {
      phaseId: data.phaseId,
      projectId: projectInfo.value.projectId,
      projectInfo: projectInfo.value,
      title,
    },
  });
};
</script>
<style lang="scss">
.empty {
  padding-top: 60rpx;
}

</style>
